﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EFFC.Net.Interface;
using EFFC.Net.Resource;
using EFFC.Net.Common;
using EFFC.Net.Returns;
using EFFC.Net.Parameters;
using EFFC.Net.Logic;
using EFFC.Net.Manager;
using EFFC.Net.BatchBuilder.Parameters;
using EFFC.Net.BatchBuilder.Returns;
using EFFC.Net.BatchBuilder.BatchLogic;
using EFFC.Net.BatchBuilder.Interface;

namespace EFFC.Net.BatchBuilder.BatchManage
{
    public abstract class BatchManager:BaseManager, IProcess
    {
        #region IProcess 成員

        public ReturnStd Run(ParametersStd p)
        {
            try
            {
                return this.MainFlowProcess(p);
            }
            catch (Exception ex)
            {
                return OnError(ex);
            }
            finally
            {
                ResouceManager.Release(this);
            }
        }

        #endregion

        protected abstract ReturnStd MainFlowProcess(ParametersStd p);
        protected virtual BatchRtn OnError(Exception ex)
        {
            BatchRtn rtn = new BatchRtn();
            rtn.IsSuccess = false;
            return rtn;
        }

        /// <summary>
        /// 標注化查詢接口
        /// </summary>
        /// <typeparam name="T">IQuery</typeparam>
        /// <param name="p"></param>
        /// <returns></returns>
        public abstract QueryReturn Query<T>(BatchManagerParameter p) where T : BatchBaseLogic, IQuery;
        /// <summary>
        /// 標注化Update接口
        /// </summary>
        /// <typeparam name="T">IUpdate</typeparam>
        /// <param name="p"></param>
        /// <returns></returns>
        public abstract bool Update<T>(BatchManagerParameter p) where T : BatchBaseLogic, IUpdate;
        /// <summary>
        /// 標注化Delete接口
        /// </summary>
        /// <typeparam name="T">IDelete</typeparam>
        /// <param name="p"></param>
        /// <returns></returns>
        public abstract bool Delete<T>(BatchManagerParameter p) where T : BatchBaseLogic, IDelete;
        /// <summary>
        /// 標注化Insert接口
        /// </summary>
        /// <typeparam name="T">IInsert</typeparam>
        /// <param name="p"></param>
        /// <returns></returns>
        public abstract bool Insert<T>(BatchManagerParameter p) where T : BatchBaseLogic, IInsert;
        /// <summary>
        /// 標注化翻页查询接口
        /// </summary>
        /// <typeparam name="T">IQueryByPage</typeparam>
        /// <param name="p"></param>
        /// <returns></returns>
        public abstract QueryByPageReturn QueryByPage<T>(BatchManagerParameter p) where T : BatchBaseLogic, IQueryByPage;
        /// <summary>
        /// 標注化Check处理接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="p"></param>
        /// <returns></returns>
        public abstract WebLogicCheckRtn Check<T>(BatchManagerParameter p) where T : BatchBaseLogic, IWebLogicCheck;
        /// <summary>
        /// 標注化获取公共参数的邏輯處理接口
        /// </summary>
        /// <typeparam name="T">WebBaseLogic, IWebLogicCheck</typeparam>
        /// <param name="p">可扩展数组</param>
        /// <returns></returns>
        public abstract CommonLogicReturn GetValue<T>(params object[] p) where T : BatchBaseLogic, ICommonLogic;
        /// <summary>
        /// 標注化判斷是否存在的邏輯處理接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="p"></param>
        /// <returns></returns>
        public abstract IsExistsRtn IsExists<T>(BatchManagerParameter p) where T : BatchBaseLogic, IIsExists;
        /// <summary>
        /// 標注化判斷是否存在的邏輯處理接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="p"></param>
        /// <returns></returns>
        public abstract IsValidRtn IsValid<T>(BatchManagerParameter p) where T : BatchBaseLogic, IIsValid;
        /// <summary>
        /// 標注化通用邏輯處理接口
        /// </summary>
        /// <typeparam name="T">BaseLogic, IBatchLogicProcess</typeparam>
        /// <param name="p">BatchManagerParameter</param>
        /// <returns>BatchLogicRtn</returns>
        public abstract BatchLogicRtn Process<T>(BatchManagerParameter p) where T : BatchBaseLogic, IBatchProcess;
    }
}
